home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CPPCOM17.ARJ / DIALER2.CPP < prev    next >
C/C++ Source or Header  |  1991-02-27  |  3KB  |  130 lines

  1. /***************************************************************************
  2. These C++ classes are copyright 1990, by William Herrera.
  3. All those who put this code or its derivatives in a commercial product MUST
  4. mention this copyright in their documentation for users of the products in
  5. which this code or its derivative classes are used.  Otherwise, this code
  6. may be freely distributed and freely used for any purpose.
  7. ***************************************************************************/
  8.  
  9. #include        <stdio.h>
  10. #include        <conio.h>
  11. #include        <string.h>
  12. #include        <stdlib.h>
  13. #include        <dos.h>
  14.  
  15. #include        "modem.hpp"
  16.  
  17. static int defaultport = 1;
  18.  
  19. static const long defaultspeed = 38400L;
  20.  
  21. // change spped to suit your application.
  22.  
  23. int xgetch(void) 
  24. {
  25.     // ibm pc keyboard extended getch().
  26.     int ch;
  27.     return ( (ch = getch()) != 0 ) ? ch : getch() + 256;
  28. }
  29.  
  30. int main(int argc, char ** argv) 
  31. {
  32.     char dialstr[256];
  33.     int port;
  34.     long speed;
  35.     switch(argc)
  36.     {
  37.         case 2: 
  38.             // one argument--dial the argument
  39.             strcpy(dialstr, argv[1]); 
  40.             port = defaultport;
  41.             speed = defaultspeed;
  42.             break;
  43.         case 3: 
  44.             // two arguments--dial the second argument using first for port
  45.             strcpy(dialstr, argv[2]); 
  46.             port = atoi(argv[1]);
  47.             speed = defaultspeed;
  48.             break;
  49.         case 4:
  50.             // first port, then speed, then number.
  51.             strcpy(dialstr, argv[3]); 
  52.             port = atoi(argv[1]);
  53.             speed = atoi(argv[2]);
  54.             break;
  55.         default:
  56.             port = defaultport;
  57.             speed = defaultspeed;
  58.             dialstr[0] = 0;
  59.             break;
  60.     }
  61.     modem m(port, speed, NOPAR, 1, 8, false);
  62.     m.RaiseDTR();
  63.  
  64.     if(dialstr[0] != 0)
  65.     {
  66.         printf("Please pick up the phone.  Press a key to continue:\n");
  67.         xgetch();
  68.         printf("Dialing %s. . .\n", dialstr);
  69.         m.Dial(dialstr);
  70.         printf("Please hit a key when dialing is complete.\n");
  71.         xgetch();
  72.     }
  73.     else        // go into open modem mode
  74.     {
  75.         printf("Current baud rate is %ld\n", m.GetSpeed());
  76.          printf("Alt-B set baud rate, Alt-D dial, Alt-H hang up, Alt-S shell, Alt-X exit\n");
  77.         while (1) 
  78.         {
  79.             int c;
  80.             if (kbhit()) 
  81.             {
  82.                 c = xgetch();
  83.                 if(c == 301)        // Alt-X to exit
  84.                     break;        // break out of while(1) loop.
  85.                 char st[212];
  86.                 switch(c)
  87.                 {
  88.                     case 304:        // Alt-B to set baud rate
  89.                         printf("\nCurrent baud rate is %ld\n", 
  90.                             m.GetSpeed());
  91.                         printf("New baud rate (300-19200): ");
  92.                         if(scanf("%7s", st) == 1)
  93.                         {
  94.                             int s = atoi(st);
  95.                             if(s > 299 && s < 19201)
  96.                                 m.SetSpeed(s);
  97.                         }
  98.                         break;
  99.                     case 288:        // Alt-D to dial
  100.                         printf("\nNumber to dial: ");
  101.                         if(scanf("%64s", st) == 1)
  102.                             m.Dial(st);
  103.                         break;
  104.                     case 287:        // Alt-S to shell
  105.                         printf("\nExternal DOS command: ");
  106.                         if(scanf("%211s", st) == 1)
  107.                             system(st);
  108.                         printf("\nExiting DOS . . . You may continue.\n");
  109.                         break;
  110.                     case 291:        // Alt-H to hang up
  111.                         m.Escape();
  112.                         m.HangUp();
  113.                         break;
  114.                     default:
  115.                         m.Send(char(c));    // avoid sending (int) c
  116.                         break;
  117.                 }    // switch(c)
  118.             }    // if kbhit()
  119.             if ((c = m.GetChar()) != -1)
  120.                 putchar(c);
  121.         }    // while(1)
  122.     }    // else
  123.     // Finished.  Clean up line before exiting to prevent lockups.
  124.     m.Escape();
  125.     m.HangUp();
  126.     m.Pause();
  127.     return 0;
  128. }
  129.  
  130.